package com.peakmain.wanandroid.netmodule.net.http.download;


import com.peakmain.wanandroid.netmodule.net.http.interceptor.LoggerInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * author ：Peakmain
 * version : 1.0
 * createTime：2020/2/22
 * mail:2726449200@qq.com
 * describe：下载管理
 */
public class DownloadManager {

    private DownloadThreadPool threadPool;                      //下载的线程池

    private OkHttpClient mOkHttpClient;

    public static DownloadManager getInstance() {
        return OkDownloadHolder.instance;
    }

    private static class OkDownloadHolder {
        private static final DownloadManager instance = new DownloadManager();
    }


    private DownloadManager() {
        threadPool = new DownloadThreadPool();

        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.readTimeout(60000, TimeUnit.MILLISECONDS);
        builder.writeTimeout(60000, TimeUnit.MILLISECONDS);
        builder.connectTimeout(60000, TimeUnit.MILLISECONDS);
        LoggerInterceptor loggerInterceptor = new LoggerInterceptor(true);
        builder.addInterceptor(loggerInterceptor);
        mOkHttpClient = builder.build();
    }

    public DownloadThreadPool getThreadPool() {
        return threadPool;
    }

    /**
     * 返回下载httpClient
     * @return
     */
    public OkHttpClient getDownOkhttpClient(){
        return mOkHttpClient;
    }
}
